#ifndef MODULE_WINDOW_H
#define MODULE_WINDOW_H

#include <QFrame>
#include <QMouseEvent>
#include <QGridLayout>
#include <QResizeEvent>
#include <QLabel>

#include "module/property/module_port_property.h"
#include "module/property/module_window_property.h"
#include "module/property/module_propertys.h"
#include "module/module_port.h"

#include "module/modulefileconfig.h"


namespace Ui {
class module_window;
}

struct Margin{
  int leftMargin;
  int topMargin;
  int rightMargin;
  int bottonMargin;
};


struct Module_Code
{
    QString module_code;
    QString user_code;
};


///---------------------------------------------------------------

class module_secondframe : public QFrame
{
    Q_OBJECT
public:
    explicit module_secondframe(QWidget *parent = nullptr);

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseDoubleClickEvent(QMouseEvent *event) override;

//    virtual void resizeEvent(QResizeEvent *event) override;

signals:
    void clicked();
    void double_clicked();

};

///---------------------------------------------------------------

class module_window : public QFrame
{
    Q_OBJECT

public:
    Margin module_window_margin;

    explicit module_window(Module_Data data, Margin first_margin, QWidget *parent = nullptr);

    void set_margin(int leftMargin, int topMargin, int rightMargin, int bottonMargin); // 设置地一层内边距
    void set_margin(Margin margin); // 设置地一层内边距

    void set_module_name(QString name);

    /// 初始化
    void init();

    void init_port(); // 创建端口

    void init_label();
    ///
    ///---------------------------------------------------------------

    QString get_module_name();
    QString get_module_type();
    QString get_module_class();
    QString code_generate();
    ~module_window();

signals:
    void changeLableName(QString name);

public slots:
    void setLableName(QString name);

    void make_window_property();
    void make_code_window();

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseDoubleClickEvent(QMouseEvent *event) override;

    virtual void resizeEvent(QResizeEvent *event) override;

private:
    Ui::module_window *ui;

    Module_Data module_data;
    Module_Code code;

    module_secondframe *second_window;

    QList<module_port *> port_list_input;
    QList<module_port *> port_list_output;
    QList<module_port *> port_list_inout;

    QLabel *ModuleLabel = new QLabel(this);

    void init_module_window_margin(int leftMargin, int topMargin, int rightMargin, int bottonMargin);

    void init_second_window(); // 创建第二层

    void move_port(module_port *port, int sum, int num);
    void move_label();


};

///---------------------------------------------------------------


#endif // MODULE_WINDOW_H
